import { Dictionary } from "@/types";
import { defineStore } from "pinia";
import { ref } from "vue";

const KEY = "id-generator";

/**
 * 获取全局唯一ID，组件级
 */
export const useIdGeneratorStore = defineStore(KEY, () => {
  const idGeneratorMapping = ref({} as Dictionary<number>);

  function incr(type: string) {
    if (!idGeneratorMapping.value[type]) {
      idGeneratorMapping.value[type] = 0;
    }
    return `paw-element-${type}-${++idGeneratorMapping.value[type]}`;
  }

  return { incr };
});
